package cn.linweijian.kafka.producerdemo.controller;

import cn.linweijian.kafka.producerdemo.service.SendService;
import cn.linweijian.kafka.producerdemo.vo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Description: kafkademo
 * <p>
 * Created by linweijian on 2018/5/31 16:25
 */
@Controller
public class Index {
    @Autowired
    private SendService sendService;

    @RequestMapping("/")
    public String index() {
        return "index";
    }
    @RequestMapping("/index2")
    public String index2() {
        return "index2";
    }

    @PostMapping("/submit")
    @ResponseBody
    public String submit(@RequestBody Article article) {
        try {
            sendService.send(article);
            return "发送成功";
        } catch (Exception e) {
            return "error";
        }
    }
}
